package profiler.exec;

import profiler.SingletonTimer;

public abstract class AbstractExecution implements Execution {

    private final Execution parent;

    private final long key;
    
    public AbstractExecution(Execution parent, long key) {
        super();
        this.key = key;
        this.parent = parent;
    }

    public AbstractExecution(long key) {
        this(null, key);
    }

    public boolean isRoot() {
        return parent == null;
    }

    public Execution parent() {
        return parent;
    }

    public long key() {
        return key;
    }

    public long avgTime() {
        return totalTimeNano() / numberOfExecutions();
    }
    
    public String getMethodName() {
        return SingletonTimer.getIdentifier(this.key);
    }
}
